package org.example.java.base;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;

public class BitSetTest {
  public List list = new ArrayList();

  private static String toBitSet(String str) {
    String result = "[";
    BitSet bitSet = new BitSet();
    byte[] strBits = str.getBytes();
    for (int i = 0; i < strBits.length * 8; i++) {
      if ((strBits[i / 8] & (128 >> (i % 8))) > 0) {
        bitSet.set(i);
      } else {
        System.out.println();
      }
    }
    for (int i = 0; i < bitSet.length(); i++) {
      if (bitSet.get(i))
        result += "1";
      else
        result += "0";
    }
    result += "]";
    return result;
  }

  public static void main(String[] args) {
//    System.out.println(toBitSet("测试一下"));
//    testBitSet();
//    testNumberOfLeadingZeros();
  }

  private static void testNumberOfLeadingZeros() {
    long test = 1;
    System.out.println(Long.numberOfLeadingZeros(test << 3));
    System.out.println(Long.numberOfLeadingZeros(test << 40));
    System.out.println(Long.numberOfLeadingZeros(test << 40 | test << 4));
  }

  private static void testBitSet() {
    BitSet bitSet = new BitSet();
    bitSet.set(1);
    bitSet.set(2);
    bitSet.set(7);
    bitSet.set(123);
    System.out.println(bitSet.get(1));
    System.out.println(bitSet.get(2));
    System.out.println(bitSet.get(7));
    System.out.println(bitSet.get(122));
    System.out.println(bitSet.get(123));
    System.out.println("======");
    BitSet bitSet2 = new BitSet();
    bitSet2.set(3);
    bitSet.or(bitSet2);
    System.out.println("bitSet has 3 :" + bitSet.get(3));

  }

}